Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
JavaScript library to generate a human readable String describing the file size
The filesize npm package is a library designed to provide simple file size conversion and formatting. It allows users to convert raw file size numbers into human-readable strings, with support for multiple units and customization options. This can be particularly useful in applications where file sizes need to be displayed to users in a format that is easy to understand.
Basic file size formatting
Converts a file size in bytes to a human-readable string using the most appropriate unit. In this example, 1024 bytes are converted to '1 KB'.
"const filesize = require('filesize');
console.log(filesize(1024)); // '1 KB'"
Customizing the output
Allows customization of the output format, including rounding and the spacer between the number and the unit. This example shows no rounding and removes the space between the number and the unit.
"const filesize = require('filesize');
console.log(filesize(1024, {round: 0, spacer: ''})); // '1KB'"
Using different units
Supports using different unit standards, such as the International Electrotechnical Commission (IEC) standard, which uses 'KiB' instead of 'KB' for 1024 bytes.
"const filesize = require('filesize');
console.log(filesize(1024, {standard: 'iec'})); // '1 KiB'"
Similar to filesize, pretty-bytes converts byte values into a human-readable format. It focuses on simplicity and does not offer as many customization options as filesize, making it a good choice for straightforward use cases.
The bytes package also provides functionality for formatting byte sizes into human-readable strings. It offers a balance between simplicity and customization, with options to specify the number of decimal places and the units to use.
filesize.js provides a simple way to get a human readable file size string from a number (float or integer) or string.
filesize()
accepts an optional descriptor Object as a second argument, so you can customize the output.
(number) Number base, default is 2
(boolean) Enables bit
sizes, default is false
(number) Specifies the symbol via exponent, e.g. 2
is MB
for base 2, default is -1
(boolean) Enables full form of unit of measure, default is false
(array) Array of full form overrides, default is []
(string) Output of function (array
, exponent
, object
, or string
), default is string
(number) Decimal place, default is 2
(string) Decimal separator character, default is .
(string) Character between the result
and suffix
, default is " "
(string) Standard unit of measure, can be iec
or jedec
, default is jedec
; can be overruled by base
(object) Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found
(object) Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found
(boolean) Enables unix style human readable output, e.g ls -lh
, default is false
filesize(500); // "500 B"
filesize(500, {bits: true}); // "4 Kb"
filesize(265318, {base: 10}); // "265.32 kB"
filesize(265318); // "259.1 KB"
filesize(265318, {round: 0}); // "259 KB"
filesize(265318, {output: "array"}); // [259.1, "KB"]
filesize(265318, {output: "object"}); // {value: 259.1, suffix: "KB", symbol: "KB"}
filesize(1, {symbols: {B: "Б"}}); // "1 Б"
filesize(1024); // "1 KB"
filesize(1024, {exponent: 0}); // "1024 B"
filesize(1024, {output: "exponent"}); // 1
filesize(265318, {standard: "iec"}); // "259.1 KiB"
filesize(265318, {standard: "iec", fullform: true}); // "259.1 kibibytes"
filesize(12, {fullform: true, fullforms: ["байтов"]}); // "12 байтов"
filesize(265318, {separator: ","}); // "259,1 KB"
filesize.partial()
takes the second parameter of filesize()
and returns a new function with the configuration applied
upon execution. This can be used to reduce Object
creation if you call filesize()
without caching the descriptor
in lexical scope.
const size = filesize.partial({standard: "iec"});
size(265318); // "259.1 KiB"
filesize.js supports AMD loaders (require.js, curl.js, etc.), node.js & npm (npm install filesize
), or using a script tag.
An ES6 version is bundled with an npm install, but requires you load it with the full path, e.g. require(path.join(__dirname, 'node_modules', 'filesize', 'lib', 'filesize.es6.js'))
.
Copyright (c) 2018 Jason Mulligan Licensed under the BSD-3 license.
FAQs
JavaScript library to generate a human readable String describing the file size
The npm package filesize receives a total of 9,831,917 weekly downloads. As such, filesize popularity was classified as popular.
We found that filesize demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.